<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .div1 {
      width: 100px;
      height: 100px;
      background-color: red;
      position: relative;
      left: 0px;
    }

    /* 显示隐藏的css */
    .v-enter-active,
    .v-leave-active {
      transition: opacity 2s;
    }

    .v-enter,
    .v-leave-to

    /* .fade-leave-active below version 2.1.8 */
      {
      opacity: 0;
    }
    /* ======================================= */
    /* 显示隐藏的css */
    .transition2-enter-active,
    .transition2-leave-active {
      transition: left 5s;
    }
    .transition2-enter {
      left: -120px;
    }
    .transition2-enter-to {
      left: 0px;
    }
    .transition2-leave-to {
      left: -120px;
    }
  </style>
</head>

<body>
  <div id="app">
    <p>过渡动画——在元素切换时更加美观</p>
    <button @click="toggle">toggle</button>
    <p>切换过程中的css，显示过程中：v-enter、v-enter-to、v-enter-active;隐藏过程中：v-leave、v-leave-to、v-leave-active</p>
    <p>transition的作用是找到对应的class，添加并在合适的时间移除。css需要自己写，class名字要按照vue的要求</p>
    <p>css动效的前缀和transition组件的name要保持一致</p>
    <transition name="transition2">
      <div class="div1" v-show="isShow"></div>
    </transition>
    <hr>
    <transition>
      <div class="div1" v-show="isShow"></div>
    </transition>
  </div>
  <script src="../vue.js"></script>
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        isShow: true
      },
      methods: {
        toggle() {
          this.isShow = !this.isShow;
        }
      },
    })
  </script>
</body>

</html>